#!/bin/sh

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'

#ssh
echo "${GREEN}install ssh!!!${NC}"
echo -e "...\n"

unlink /bin/passwd
ln -s /bin/busybox /bin/passwd
ln -s /bin/busybox /bin/syslogd
ln -s /bin/busybox /bin/klogd

mkdir -p /var/empty/

if pgrep syslogd > /dev/null; then
    # 如果pgrep找到了syslogd进程，说明syslogd正在运行
    echo "${GREEN}restart syslogd${NC}"
    killall syslogd
    syslogd -O /data/log/sys/messages -s 1024 -b 0

else
    # 如果没有找到syslogd进程，启动syslogd
    echo "${GREEN}syslogd no run,start...${NC}"
    syslogd -O /data/log/sys/messages -s 1024 -b 0
fi

if pgrep klogd > /dev/null; then
    # 如果pgrep找到了syslogd进程，说明syslogd正在运行
    echo "${GREEN}klogd running${NC}"

else
    # 如果没有找到syslogd进程，启动syslogd
    echo "${GREEN}klogd no run,start...${NC}"
    klogd
fi

[ -f /data/openssh/ssh_host_rsa_key ] || ssh-keygen -t rsa -f /data/openssh/ssh_host_rsa_key -N ""

echo -e "\n"
/system/bin/sshd -f /etc/openssh/sshd_config -h /data/openssh/ssh_host_rsa_key

echo "${GREEN}install finish${NC}"
